#include <bits/stdc++.h>

using namespace std;

#define data DATA

const int MAXN = 1e5+10;
const int inf = 0x3f3f3f3f;

typedef struct {int v,nxt;}edge;

int h[MAXN],n,dfn[MAXN],tot,cnt,siz[MAXN],top[MAXN],fa[MAXN];
int son[MAXN],ex[MAXN],ey[MAXN],dep[MAXN];

edge e[MAXN<<1];

void link(int x,int y){e[++cnt] = edge{y,h[x]};h[x] = cnt;}


struct data{
	int mn,eval;
	friend bool operator < (data a,data b){
		return a.mn < b.mn;
	}
	friend void operator += (data &a,data b){
		a.mn += b.mn;
		a.eval ^= b.eval;
	}
}tag[MAXN<<2];

struct node{
	data v; int id;
	friend node operator + (node a,node b){
		return a.v < b.v ? a:b;
	}
}val[MAXN<<2];

void dfs(int x,int p){
	siz[x] = 1;son[x] = 0;fa[x] = p;dep[x] = dep[p]+1;
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v;
		if(y == p) continue;
		dfs(y,x);
		siz[x] += siz[y];
		if(siz[y] > siz[son[x]]) son[x] = y;
	}
}

void dfs2(int x,int anc){
	top[x] = anc;dfn[x] = ++tot;
	if(son[x]) dfs2(son[x],anc);
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v;
		if(y == son[x] || y == fa[x]) continue;
		dfs2(y,y);
	}
}

void build(int o = 1,int l = 1,int r = n){
	if(l == r){
		val[o].id = l;
		val[o].v = (data){0,0};
		return;
	}
	int mid = (l+r)>>1;
	build(o<<1,l,mid);build(o<<1|1,mid+1,r);
	val[o] = val[o<<1] + val[o<<1|1];
}

void pushdown(int o){
	if(tag[o].mn || tag[o].eval){
		tag[o<<1] += tag[o];
		tag[o<<1|1] += tag[o];
		val[o<<1].v += tag[o];
		val[o<<1|1].v += tag[o];
		tag[o] = (data){0,0};
	}
}

void add(int xl,int xr,data v,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r){
		val[o].v += v;
		tag[o] += v;
		return;
	}
	pushdown(o);
	int mid = (l+r)>>1;
	if(xr <= mid) add(xl,xr,v,o<<1,l,mid);
	else if(xl > mid) add(xl,xr,v,o<<1|1,mid+1,r);
	else add(xl,mid,v,o<<1,l,mid),add(mid+1,xr,v,o<<1|1,mid+1,r);
	val[o] = val[o<<1] + val[o<<1|1];
}

void modify(int x,int y,data v){
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		add(dfn[top[x]],dfn[x],v);
		x = fa[top[x]];
	}
	if(dfn[x] > dfn[y]) swap(x,y);
	if(dfn[x] != dfn[y]) add(dfn[x]+1,dfn[y],v);
}

int main (){
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int x,y;scanf("%d %d",&x,&y);
		link(x,y); link(y,x);
	}
	dfs(1,0);
	dfs2(1,1);
	build();
	add(1,1,(data){inf,0});
	for(int i = 1;i < n;i++){
		scanf("%d %d",&ex[i],&ey[i]);
		modify(ex[i],ey[i],(data){1,i});
	}
	for(int i = 1;i < n;i++){
		if(val[1].v.mn != 1){
			puts("NO");
			return 0;
		}
		int num = val[1].v.eval;
		int nodenum = val[1].id;
		add(nodenum,nodenum,(data){inf,0});
		modify(ex[num],ey[num],(data){-1,num});
	}
	printf("YES");
	return 0;
}
